package com.sqsf.test;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

//读取jdbc.properties配置文件数据
@PropertySource("classpath:jdbc.properties")
//<context:property-placeholder location="classpath:jdbc.properties"/>
public class DruidConfig {
    //需要我们声明变量使用@Valve("name")进行获取赋值
    @Value("${jdbc.driver}")
    private String driver;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;



    //因为无法书写注解所以无法使用无参构造方法形式创建
    //可以书写方法 返回对象交由spring容器管理
    //    <bean id="druid" factory-bean="springConfig" factory-method="druid"/>
    @Bean("druid")
    public DruidDataSource druid(){
        DruidDataSource druid=new DruidDataSource();
        druid.setDriverClassName(driver);
        druid.setUrl(url);
        druid.setUsername(username);
        druid.setPassword(password);
        return druid;
    }
}
